#include "AISeperation.h"
#include "Agent.h"
#include "Game.h"
#include "ObjMeshManager.h"

AISeperation::AISeperation()
{

}

void AISeperation::Update()
{
	Neighbours n = m_agent->GetNeighbours();
	int numOfNeighbours = n.size();
	
	D3DXVECTOR3 centre = D3DXVECTOR3(0.0f, 0.0f, 0.0f);	
	for (int i = 0; i != numOfNeighbours; i++)
	{
		//D3DXVECTOR3 pos = n[i]->GetPosition();
			
		centre += n[i]->GetPosition();
	}
		
//	D3DXVECTOR3 mazeCellSize = TheGame::Instance()->GetMaze()->GetCellSize();
//	D3DXVECTOR2 mazeSize = TheGame::Instance()->GetMaze()->GetGridSize();
	
	//centre /= numOfNeighbours;

	D3DXVECTOR3 tPos = centre;
	//tPos.x -= mazeCellSize.x * (mazeSize.x * 0.5f);
	//tPos.z -= mazeCellSize.z * (mazeSize.y * 0.5f); 
	//tPos.y = mazeCellSize.y * 1.5f;

	//centre = tPos;

	//TheObjMeshManager::Instance()->Translate("sphere", centre);
	//TheObjMeshManager::Instance()->Scale("sphere", D3DXVECTOR3(5.0f, 5.0f, 5.0f));
	//TheObjMeshManager::Instance()->Draw("sphere");

	//centre *= (1.0f / (float)numOfNeighbours);

	// run away from surrounding neighbours
//	tPos = m_agent->GetPosition();
//	tPos.x -= mazeCellSize.x * (mazeSize.x * 0.5f);
//	tPos.z -= mazeCellSize.z * (mazeSize.y * 0.5f); 
//	tPos.y = mazeCellSize.y * 1.5f;
	
	//TheObjMeshManager::Instance()->Translate("sphere", tPos);
	//TheObjMeshManager::Instance()->Scale("sphere", D3DXVECTOR3(3.0f, 3.0f, 3.0f));
	//TheObjMeshManager::Instance()->Draw("sphere");

	D3DXVECTOR3 direction = centre - tPos;
	m_agent->AddForce(-direction);
}